package com.hope.onlinestudy.activity.login

import android.view.View
import com.hope.onlinestudy.BuildConfig
import com.hope.onlinestudy.R
import com.hope.onlinestudy.activity.start.StartActivity
import com.hope.onlinestudy.mvp.MVPBaseActivity
import com.hope.onlinestudy.utils.PreferencesUtils
import kotlinx.android.synthetic.main.activity_login.*
import kotlinx.android.synthetic.main.view_title.*
import org.jetbrains.anko.startActivity

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */
class LoginActivity : MVPBaseActivity<LoginContract.View, LoginPresenter>(), View.OnClickListener,
    LoginContract.View {
    private var username: String? = null
    private var userpwd: String? = null

    override fun getLayoutView(): Int {
        return R.layout.activity_login
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.btnSubmit -> {
                username = etAccount.text.toString().trim()
                userpwd = etPass.text.toString().trim()
                mPresenter?.login(username, userpwd)
            }
            R.id.iv_backup -> finish()
        }
    }

    override fun initData() {
        tv_title.text = "登录"
        btnSubmit.setOnClickListener(this)
        iv_backup.setOnClickListener(this)

        username = PreferencesUtils.getString(this, "username")
        userpwd = PreferencesUtils.getString(this, "userpwd")
        if (BuildConfig.LOG_DEBUG) {
            username = "zxstudent1"
            userpwd = "123456"
        }
        etAccount.setText(username)
        etPass.setText(userpwd)

        mPresenter?.getConfigSystem()
    }

    override fun loginSuccess() {
        startActivity<StartActivity>()
    }
}